'''
The Order Taker User Interface for the coffee bar workflow (Winter Intensives Lab 5)

This is where you define the fields that appear on the screen (application) the order
taker sees and tell WMP how this application (user interface) fits into the overall
workflow.

Note:  the comments here assume you have already read through the comments
in CoffeeBackend.py and made your edits there.
'''

# these next few lines import some of the WMP functions we will
# use in this file.
from frontend.roleApplication import RoleApplication
from frontend.form import Type
import csv
import menu
import menuItem


class CustomerApplication(RoleApplication):
    def get_menu(self, file, title="Ruglist"):
        csvfile = open(file, "rU")
        dialect = csv.Sniffer().sniff(csvfile.read(1024))
        csvfile.seek(0)
        menuReader = csv.reader(csvfile, dialect)
        myMenu = menu.menu(title)
        for row in menuReader:
            myMenuItem = menuItem.MenuItem(row[0], float(row[1]), row[2])
            myMenu.items.append(myMenuItem)
        return myMenu
    

    def __init__(self):
      
        super(CustomerApplication, self).__init__("RugsWorkflow", "Customer") # use actual work flow name and role name
        self.register_source_step("PlaceOrder", self.take_order_form_creator) # use actual name for this task

    def take_order_form_creator(self, stepname, form):
        
        form.add_static_label('Shipping available only in US and Canada:')
        form.add_field(Type.SHORTSTRING, "FullName")
        form.add_field(Type.SHORTSTRING, "Address")
        form.add_field(Type.SHORTSTRING, "City", labeltext="City, State, Zip")
        form.add_field(Type.SHORTSTRING, "Email")
        form.add_static_label('')
        form.add_static_label('Choose rug type below:') # improve this text!
        
        menu = self.get_menu("RugType4.csv")
        for item in menu.getItems():
            field = item.getName() + " " + item.getType()
            label = item.getName() + " " + item.getType() + " $" + str(item.getPrice())
            form.add_field(Type.BOOLEAN, field, labeltext=label)
        
        form.add_static_label('Enter Payment Details:') # improve this text!
        form.add_field(Type.SHORTSTRING, "CCNumber", labeltext="Credit Card Number") 
        form.add_field(Type.CHOICE, "CCType", labeltext="Credit Card Type", choices=["Visa", "Mastercard","American Express","Discover"])
        form.add_field(Type.SHORTSTRING, "CCMonth", labeltext="Expiration Month") 
        form.add_field(Type.SHORTSTRING, "CCYear", labeltext="Expiration Year")
        
        # add at least two fields here, along with any additional static labels you need

if __name__ == '__main__':
    app = CustomerApplication()
    app.MainLoop()